package com.smedi.ismedi.constructionproject.core.port.adapter.service.impl;

import com.smedi.ismedi.constructionproject.core.infrastructure.constant.CustomError;
import com.smedi.ismedi.constructionproject.core.port.adapter.service.InmallRemoteApiService;
import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteOverviewFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.LogicException;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: InmallRemoteApiServiceImpl
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2023/12/7 16:29
 */

@Service
@Slf4j
@AllArgsConstructor
public class InmallRemoteApiServiceImpl implements InmallRemoteApiService {

    private final RemoteOverviewFeignApi remoteOverviewFeignApi;

    @Override
    public Boolean hasDing(Long personId) {
        ResponseData<Boolean> responseData = remoteOverviewFeignApi.peopleExist(personId);
        if (!responseData.isSuccess()) {
            throw LogicException.raise(CustomError.CALL_REMOTE_API_ERROR, responseData.getApplication(), String.valueOf(responseData.getErrorMsg()));
        }
        return responseData.getData();
    }

    @Override
    public List<String> getUsersByProjectId(Long projectId) {
        ResponseData<List<String>> responseData = remoteOverviewFeignApi.peopleByProjectId(projectId);
        if (!responseData.isSuccess()) {
            throw LogicException.raise(CustomError.CALL_REMOTE_API_ERROR, responseData.getApplication(), String.valueOf(responseData.getErrorMsg()));
        }
        return responseData.getData();
    }
}